home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8784 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: lrz-muenchen.de!news
  2. From: watzka@stat.uni-muenchen.de (Kurt Watzka)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Very Newbie question on pointers
  5. Date: 6 Mar 1996 11:08:04 GMT
  6. Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
  7. Distribution: world
  8. Message-ID: <4hjrmk$snr@sparcserver.lrz-muenchen.de>
  9. References: <bantolov-0603960018080001@bantolov.seanet.com>
  10. NNTP-Posting-Host: sun2.lrz-muenchen.de
  11.  
  12. bantolov@bantolov.seanet.com (Bruce Antolovich) writes:
  13.  
  14. >I hope that this is the right place to post such a question; if not, sorry
  15. >for the wasted bandspace.
  16.  
  17. >I am very new to programming in C but have a large background in FORTRAN.
  18. >(please no snickers) I am having a problem with the memory location of
  19. >variables as described by pointers. I define several variables and try to
  20. >get their address in memory. Unfortunately, my code gives me the same
  21. >address for all variables! Any clues as to where I'm going wrong would be
  22. >very appreciated.
  23.  
  24. >I don't think that it matters but I'm using Metrowerks CW on a PowerMac
  25. >6100/60.
  26.  
  27. >Here is my sample code. (it does work correctly numerically)
  28.  
  29. >#include <stdio.h>
  30.  
  31. >/***********************/
  32. >/* Function Prototypes */
  33. >/***********************/
  34. >void  SquareIt( int  number, int *squarePtr, int *cubePtr );
  35.  
  36. >int main (void)
  37. >{
  38.  
  39. >   int square;
  40. >   int cube;
  41. >   int *myCube;
  42. >   int *mySquare;
  43. >   double test;
  44. >   mySquare = □
  45. >   myCube = &cube;
  46. >   printf("%d \n",&test);
  47.  
  48.     printf("%p \n", (void *) &test);
  49.  
  50. "%p" expects a void pointer, "%d" expects an int. Rule 1 for working
  51. with pointers: Pointers are _not_ integers.
  52.  
  53. This problem continues through the rest of your example.
  54.  
  55. Kurt
  56. --
  57. | Kurt Watzka                             Phone : +49-89-2180-6254
  58. | watzka@stat.uni-muenchen.de
  59. | ua302aa@sunmail.lrz-muenchen.de
  60.